package jjn.effective_java.chapter6.item34;

/**
 * @author Jiang Jining
 * @since 2023-04-26 23:12
 */
public enum OperationV3 {
    
    PLUS("+") {
        @Override
        public double apply(double x, double y) {
            return x + y;
        }
    },
    
    MINUS("-") {
        @Override
        public double apply(double x, double y) {
            return x - y;
        }
    },
    
    TIMES("*") {
        @Override
        public double apply(double x, double y) {
            return x * y;
        }
    },
    
    DIVIDE("/") {
        @Override
        public double apply(double x, double y) {
            return x / y;
        }
    };
    
    public abstract double apply(double x, double y);
    
    private final String symbol;
    
    OperationV3(String symbol) {
        this.symbol = symbol;
    }
    
    @Override
    public String toString() {
        return symbol;
    }
}
